﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ZhaoXi.MSACommerce.UserService.Infrastructure.Tools
{
    public static class Md5Helper
    {
        public static string MD5EncodingOnly(string content)
        {
            var md5 = MD5.Create();
            var bs = Encoding.UTF8.GetBytes(content);
            var hs = md5.ComputeHash(bs);
            var stb = new StringBuilder();
            foreach (var b in hs)
            {
                stb.Append(b.ToString("x2"));
            }

            return stb.ToString();
        }

        public static string MD5EncodingWithSalt(string content, string salt)
        {
            return string.IsNullOrEmpty(salt) ? content : MD5EncodingOnly(content + "{" + salt + "}");
        }
    }
}
